<?php


namespace RedMVC\Form\Validator;

/**
 * Equal class
 *  
 * @category    RedMVC
 * @package     Form
 * @subpackage  Validator 
 * @author      Jan Fischer, bitWorking <info@bitworking.de>
 */
class Equal extends AValidator{
    
    private $varname = null;
    
    public function __construct($varname){
        $this->varname = $varname;
    }

    public function isValid($value, $formValues = null){
        if(!array_key_exists($this->varname, $formValues)){
            $this->setError('FORM_VALIDATOR_EQUAL_1', $this->varname);
            return false;
        }
        
        $otherValue = $formValues[$this->varname]; 
    
        if($value != $otherValue){
            $this->setError('FORM_VALIDATOR_EQUAL_2');
            return false;
        }
        return true;
    }
}